package com.shop.admin.controller;

import com.shop.admin.entity.Organization;
import com.shop.admin.entity.ShopAdmin;
import com.shop.admin.interceptors.JWTInterceptor;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.OrganizationService;
import com.shop.admin.service.ShopAdminService;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.vo.AdminNameVo;
import com.shop.admin.vo.AdminStatusVo;
import com.shop.admin.vo.SeckillStatusVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = {"AdminController"},description = "管理员接口")
@RestController
@RequestMapping("api/admin")
public class AdminController {

    @Resource
    private ShopAdminService shopAdminService;
    @Autowired
    private OrganizationService organizationService;
    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "管理员列表查询",notes = "page,limit")
    public ApiResult list(@ApiParam("参数为：page,limit")@RequestParam Map<String, Object> params){
        PageUtils page = shopAdminService.queryPage(params);
        return ApiResult.ok(page);
    }

    /*
    鉴权之前接口
     */
    @GetMapping("/info")
    @ApiOperation(value = "组织信息",notes = "")
    public ApiResult admininfo(){
        String adminId =  JWTInterceptor.userId;
        ShopAdmin byId = shopAdminService.getById(adminId);
        Organization organization = organizationService.getById(byId.getOrgId());
        organization.setAccountIncome(null);
        return ApiResult.ok(organization);
    }


    /**
     * 禁用
     */
    @PostMapping("/update/status")
    @ApiOperation(value = "设置管理员状态",notes = "id,status,updateAdminId")
    public ApiResult status(@ApiParam("参数为：id,状态(0为禁用,1为正常),修改者id")@RequestBody AdminStatusVo statusVO){
        shopAdminService.adminStatus(statusVO);
        return ApiResult.ok("状态修改成功！");
    }

    @GetMapping("/name")
    @ApiOperation(value = "管理员信息",notes = "")
    public ApiResult name(@ApiParam("参数为：")@RequestParam Map<String, Object> params){
        AdminNameVo vo = shopAdminService.getAdminName(params);
        return ApiResult.ok(vo);
    }

}
